/*
 * @Author: lsp<286212824@qq.com>
 * @Date: 2020-07-14 14:08:40
 * @LastEditTime: 2020-07-14 20:49:03
 * @Description: file content
 */
import Vue from 'vue';
import VueRouter from 'vue-router';
import Login from '@/views/index/login';

Vue.use(VueRouter);

const routes = [
  {
    path: '/',
    name: 'login',
    meta: { title: '' },
    component: Login
  },
  {
    path: '/404',
    component: () => import('@/views/404')
  },
  {
    path: '/home',
    name: 'home',
    meta: { title: '资产管理' },
    component: () => import('@/views/index/home')
  },
  {
    path: '/empty',
    name: 'empty',
    meta: { title: '资产管理' },
    component: () => import('@/views/empty')
  },
  {
    path: '/consumable-empty',
    name: 'consumable-empty',
    meta: { title: '耗材管理' },
    component: () => import('@/views/empty/consumable-empty')
  },
  {
    path: '/empty/my-empty',
    name: 'my-empty',
    meta: { title: '我的报表' },
    component: () => import('@/views/empty/my-empty')
  },
  {
    path: '/empty/dept-empty',
    name: 'dept-empty',
    meta: { title: '部门报表' },
    component: () => import('@/views/empty/dept-empty')
  },
  {
    path: '/empty/company-empty',
    name: 'company-empty',
    meta: { title: '公司报表' },
    component: () => import('@/views/empty/company-empty')
  },
  {
    path: '/helpTemp',
    name: 'helpTemp',
    meta: { title: '帮助中心' },
    component: () => import('@/views/helpTemp/index')
  },
  {
    path: '/helpTemp/helpTabDetails',
    name: 'helpTabDetails',
    meta: { title: '帮助中心' },
    component: () => import('@/views/helpTemp/tabDetails')
  },
  {
    path: '/helpTemp/helpDetails',
    name: 'helpDetails',
    meta: { title: '帮助中心' },
    component: () => import('@/views/helpTemp/details')
  }
];

const routerContext = require.context('./modules', true, /\.js$/);
routerContext.keys().forEach(route => {
  const routerModule = routerContext(route);
  // 兼容 import export 和 require module.export 两种规范
  const routeContent = (routerModule.default || routerModule);
  if (Array.isArray(routeContent)) {
    routes.push(...routeContent);
  }
});

// 404 page must be placed at the end !!!
routes.push({ path: '*', redirect: '/404' });
// console.log(routes);

const createRouter = () => new VueRouter({
  // mode: 'history', // require service support
  base: process.env.BASE_URL,
  scrollBehavior: () => ({ y: 0 }),
  routes
});

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter () {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
